package cn.ddiancan.xddcloud.psc.flow.feign;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import cn.ddiancan.xddcloud.psc.flow.utils.Assert;
import cn.ddiancan.xddcloud.psc.flow.entity.XddHisTask;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 历史任务数据访问层接口
 */
@FeignClient(contextId = "XddHisTaskService", name = "xddcloud-flow-server")
public interface XddHisTaskRemoteService {

    @PostMapping("/flow/hisTask/insert")
    boolean insert(@RequestBody XddHisTask hisTask);

    @DeleteMapping("/flow/hisTask/deleteById/{id}")
    boolean deleteById(@PathVariable("id") Long id);

    @DeleteMapping("/flow/hisTask/deleteByIds")
    boolean deleteByInstanceIds(@RequestBody List<Long> instanceIds);

    @PutMapping("/flow/hisTask/updateById")
    boolean updateById(@RequestBody XddHisTask hisTask);

    @GetMapping("/flow/hisTask/selectById/{id}")
    XddHisTask selectById(@PathVariable("id") Long id);

    default XddHisTask selectCheckById(Long id) {
        XddHisTask flwHisTask = selectById(id);
        Assert.isNull(flwHisTask, "The specified hisTask [id=" + id + "] does not exist");
        return flwHisTask;
    }

    @GetMapping("/flow/hisTask/selectListByInstanceIdAndTaskName/{instanceId}/{taskName}")
    List<XddHisTask> selectListByInstanceIdAndTaskName(@PathVariable("instanceId") Long instanceId,
        @PathVariable("taskName") String taskName);

    @GetMapping("/flow/hisTask/selectListByInstanceId/{instanceId}")
    Optional<List<XddHisTask>> selectListByInstanceId(@PathVariable("instanceId") Long instanceId);

    @GetMapping("/flow/hisTask/selectListByCallProcessIdAndCallInstanceId/{callProcessId}/{callInstanceId}")
    List<XddHisTask> selectListByCallProcessIdAndCallInstanceId(@PathVariable("callProcessId") Long callProcessId,
        @PathVariable("callInstanceId") Long callInstanceId);

    @GetMapping("/flow/hisTask/selectListByParentTaskId/{parentTaskId}")
    List<XddHisTask> selectListByParentTaskId(@PathVariable("parentTaskId") Long parentTaskId);

    @GetMapping("/flow/hisTask/selectListByInstanceIdAndTaskNameAndParentTaskId/{instanceId}/{taskName}/{parentTaskId}")
    Collection<XddHisTask> selectListByInstanceIdAndTaskNameAndParentTaskId(@PathVariable("instanceId") Long instanceId,
        @PathVariable("taskName") String taskName, @PathVariable("parentTaskId") Long parentTaskId);
}
